package com.sikiedu.logindemo2.service;

import com.sikiedu.logindemo2.dao.UserMapper;
import com.sikiedu.logindemo2.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean login(User user) {
       User res  = userMapper.findUserByUsernameAndPassword(user);
       return res!=null;
    }

    @Override
    public boolean register(User user) {
        User res  =  userMapper.findUserByUsername(user);
        if(res == null){
            userMapper.addUser(user);
            return true;
        }else{
           return false;
        }
    }
}
